//
//  MPlusMyClassViewController.m
//  medicineplus
//
//  Created by gufei on 15-5-14.
//  Copyright (c) 2015年 chn_ruby@126.cn. All rights reserved.
//

#import "MPlusMyClassViewController.h"
#import "MPlusMyClassBooksListViewController.h"
#import "MPlusMyClassExamPaperListViewController.h"
#import "MPlusMyClassVideoListViewController.h"
#import "MPlusUtils.h"
#import "MPlusDefine.h"
#import "MPlusString.h"

@interface MPlusMyClassViewController() <ViewPagerDataSource, ViewPagerDelegate> {
    NSMutableArray *mTitleArray;
    NSMutableArray *mContrlArray;
}

@end

@implementation MPlusMyClassViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self setTabBarResource:kTabBarTitleMyClass setImage:kTabBarImageMyClass setSelectedImage:kTabBarSelectedImageMyClass];
        [self setNavigationTitle:kNavTitleMyClass];
    }
    return self;
}

- (void)viewDidLoad {
    self.dataSource = self;
    self.delegate = self;
    
    // Keeps tab bar below navigation bar on iOS 7.0+
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    
    mTitleArray = [[NSMutableArray alloc] initWithCapacity:3];
    [mTitleArray addObject:kLabelBooks];
    [mTitleArray addObject:kLabelExamPapers];
    [mTitleArray addObject:kLabelVideo];
    
    mContrlArray = [[NSMutableArray alloc] initWithCapacity:3];
    MPlusMyClassBooksListViewController *booksCtrl = [[MPlusMyClassBooksListViewController alloc] initWithNibName:nil bundle:nil];
    [mContrlArray addObject:booksCtrl];
    
    MPlusMyClassExamPaperListViewController *examCtrl = [[MPlusMyClassExamPaperListViewController alloc] initWithNibName:nil bundle:nil];
    [mContrlArray addObject:examCtrl];
    
    MPlusMyClassVideoListViewController *Videoctrl = [[MPlusMyClassVideoListViewController alloc] initWithNibName:nil bundle:nil];
    [mContrlArray addObject:Videoctrl];
    
    [super viewDidLoad];
}

#pragma mark - ViewPagerDataSource
- (NSUInteger)numberOfTabsForViewPager:(ViewPagerController *)viewPager {
    return 3;
}

- (UIView *)viewPager:(ViewPagerController *)viewPager viewForTabAtIndex:(NSUInteger)index {
    
    UILabel *label = [UILabel new];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont systemFontOfSize:14.0];
    label.text = mTitleArray[index];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor blackColor];
    [label sizeToFit];
    
    return label;
}

- (UIViewController *)viewPager:(ViewPagerController *)viewPager contentViewControllerForTabAtIndex:(NSUInteger)index {
    return mContrlArray[index];
}

#pragma mark - ViewPagerDelegate
- (CGFloat)viewPager:(ViewPagerController *)viewPager valueForOption:(ViewPagerOption)option withDefault:(CGFloat)value {
    CGFloat result = 0.0;
    switch (option) {
        case ViewPagerOptionStartFromSecondTab:
            result = 0.0;
            break;
        case ViewPagerOptionCenterCurrentTab:
            result = 0.0;
            break;
        case ViewPagerOptionTabLocation:
            result = 1.0;
            break;
        case ViewPagerOptionTabWidth:
            result = SCREEN_WIDTH/3;
            break;
        default:
            result = value;
            break;
    }
    return result;
}

- (UIColor *)viewPager:(ViewPagerController *)viewPager colorForComponent:(ViewPagerComponent)component withDefault:(UIColor *)color {
    
    switch (component) {
        case ViewPagerIndicator:
            return [[MPlusUtils colorWithHexString:kBlueColor] colorWithAlphaComponent:1];
            break;
        default:
            break;
    }
    
    return color;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
